import Vue from 'vue'
import VueRouter from 'vue-router'
import historicalOrders from "@/components/historicalOrders";
import editHistoricalOrders from "@/components/editHistoricalOrders";
import Index from "@/components/Index";
import address from "@/components/address";
import allocation from "@/components/allocation";
import yardman from "@/components/yardman";
import customer from "@/components/customer";
import admin from '@/components/admin'
import login from "@/components/login";
import consumer from "@/components/consumer";
import shopPage from "@/components/shopPage";
import shopGoods from "@/components/shopGoods";
import operationalData from "@/components/operationalData";
import shoppingCart from "@/components/shoppingCart";
import shops from "@/components/shops";
import goodsType from "@/components/goodsType";
import shopType from "@/components/shopType";
import courier from "@/components/courier";
import delivery from "@/components/delivery";
import district from "@/components/district";
Vue.use(VueRouter)

function courierLogin() {

}

const routes = [
  {
    path: '/',
    component: Index,
    children:[
      {
        path:'/historicalOrders',
        component: historicalOrders
      },
      {
        path: '/shops',
        component: shops
      },
      {
        path: '/goodsType',
        component: goodsType
      },
      {
        path: '/shopType',
        component: shopType
      },
      {
        path:'/editHistoricalOrders',
        component: editHistoricalOrders,
      },
      {
        path: '/address',
        component: address
      },
      {
        path: '/customer',
        component: customer
      },
      {
        path:'/yardman',
        component: yardman
      },
      {
        path: '/admin',
        component: admin
      },
      {
        path: '/courier',
        component: courier
      },{
        path: '/district',
        component: district,
      }

    ]
  },
  {
    path: '/shoppingCart',
    component: shoppingCart
  },
  {
    path:'/login',
    component: login
  },
  {
    path: '/consumer',
    component: consumer
  },
  {
    path: '/shopPage',
    /*redirect:'/operationalData',*/
    component: shopPage,
    children: [
      {
        path: '/shopGoods',
        component: shopGoods
      },
      {
        path: '/operationalData',
        component: operationalData
      },
    ]
  },
  {
    path: '/allocation',
    component: allocation,
  },
  {
    path: '/delivery',
    component: delivery,
  }


]

const router = new VueRouter({
  mode: 'history',
  base: process.env.BASE_URL,
  routes
})
router.beforeEach((to,from,next)=>{
  if(to.path==='/login'){
    next()
  }else {
    let user=JSON.parse(sessionStorage.getItem('user'))
    if(user){
      next()
    }else {
      next('/login')
    }
  }
})
export default router
